﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Mechanics.GameEventMechanics {
    import Events.*;
    import Classes.*;
    import Display.*;
    import Display.Toaster.*;
    import Modules.stats.types.*;

    public class MallHarvestMechanic extends StorageStateHarvestMechanic {

        protected static const BASE_HARVEST_BONUS_TOASTER_SEEN_FLAG:String = "toaster_mall_harvest_bonus_";
        protected static const BASE_HARVEST_BONUS_TICKER_SEEN_FLAG:String = "ticker_mall_harvest_bonus_";

        protected var m_foundMysteryBus:String = "";

        public function get mysteryBusinessRequirement():int{
            return (m_config.params["mysteryBusinessReq"]);
        }
        override protected function preHarvest(_arg1:GenericPopupEvent):void{
            m_doobers = [];
            var _local2:Object = m_owner.getDataForMechanic(m_config.type);
            var _local3:Array = (_local2["resources"] as Array);
            if (_local3.length >= m_config.params["mysteryBusinessReq"]){
                m_doobers = m_doobers.concat(Global.player.processRandomModifiers(m_owner.getItem(), m_owner, true, [], m_owner.getItemName()));
            } else {
                if (m_config.params["previousState"]){
                    m_doobers = m_doobers.concat(Global.player.processRandomModifiers(m_owner.getItem(), m_owner, true, [], m_config.params["previousState"]));
                };
            };
            if (m_doobers.length > 0){
                this.m_foundMysteryBus = ((m_doobers[0] as Array)[0] as String);
            };
            m_owner.trackAction(TrackedActionType.PLANT);
        }
        override protected function postHarvest(_arg1:GenericPopupEvent):void{
            var _local3:String;
            var _local4:String;
            var _local5:Number;
            var _local6:int;
            var _local7:Item;
            var _local8:String;
            var _local9:String;
            var _local10:String;
            var _local11:Object;
            var _local12:ItemToaster;
            var _local13:String;
            var _local14:Object;
            var _local2:Object = m_owner.getDataForMechanic(m_config.type);
            if (!_local2){
                if (((m_config.params["ticker"]) || (m_config.params["toaster"]))){
                    _local3 = m_owner.getItemName();
                    _local4 = m_owner.getItemFriendlyName();
                    _local5 = ItemBonus.getBonusModifier(m_owner, ItemBonus.ALL);
                    _local6 = 0;
                    if (_local5 > 1){
                        _local6 = Math.round(((_local5 - 1) * 100));
                    };
                    _local7 = m_owner.getItem();
                    _local8 = (BASE_HARVEST_BONUS_TICKER_SEEN_FLAG + _local3);
                    _local9 = (BASE_HARVEST_BONUS_TOASTER_SEEN_FLAG + _local3);
                    if (((m_config.params["toaster"]) && (!(Global.player.getSeenFlag(_local9))))){
                        _local10 = String(m_config.params["toaster"]);
                        _local11 = _local7.getToasterInfo(_local10);
                        if (_local11){
                            Global.player.setSeenFlag(_local9);
                            _local12 = new ItemToaster(ZLoc.t("Main", _local11.title, {item:_local4}), ZLoc.t("Main", _local11.text, {
                                item:_local4,
                                bonus:_local6
                            }), Global.getAssetURL(_local11.asset));
                            Global.ui.toaster.show(_local12);
                        };
                    } else {
                        if (((m_config.params["ticker"]) && (!(Global.player.getSeenFlag(_local8))))){
                            _local13 = String(m_config.params["ticker"]);
                            _local14 = _local7.getTickerInfo(_local13);
                            if (_local14){
                                Global.player.setSeenFlag(_local8);
                                Global.ui.showTickerMessage(ZLoc.t("Main", _local14.text, {
                                    item:_local4,
                                    bonus:_local6
                                }));
                            };
                        };
                    };
                };
                (m_owner as IMerchant).updatePeepSpawning();
            };
        }
        override protected function onDoobersCollected():void{
            var _local1:Item;
            var _local2:String;
            var _local3:String;
            if (this.m_foundMysteryBus){
                _local1 = Global.gameSettings.getItemByName(this.m_foundMysteryBus);
                _local2 = ZLoc.t("Items", (this.m_foundMysteryBus + "_friendlyName"));
                _local3 = ZLoc.t("Dialogs", "MysteryBusFound", {bus:_local2});
                UI.displayMessage(_local3, 0, null, "", true);
            };
        }

    }
}//package Mechanics.GameEventMechanics 
